/*
Generic Doubly Linked List and Persistent Settings project
Author: Mark Newcomb Jr.

*/
#ifndef FILE_STORAGE_H
#define FILE_STORAGE_H


#include <string>
#include <fstream>
#include "DLList.h"
#include "SettingStorage.h"

#include <iostream>

#ifndef MYDEBUG
#define MYDEBUG
#endif

//class meant to store values from a DLList into a file and also to read
//values from a file into a DLList

class FileStorage : public SettingStorage
{

public:
	
	//open a file...dereferences pointer to DLList and changes that value directly
	FileStorage(DLList<std::string>* list, std::string fname = "settings.ini")
	: filename(fname),p_list(list){/*this->Load(filename);*/} //loading is disabled...it doesn't work yet
	
	//calls save with the default filename
	~FileStorage();
	
	void Copy_List_From(DLList<std::string>* list)
	{
		p_list = list;
	}
		
	
	//uses p_list and saves each setting to the file, one line per setting
	//format: "setting_name" "setting_value"
	bool Save(std::string fname);
	bool Save();
	

private:
	
	std::string filename;
	DLList<std::string>* p_list;
	std::fstream filestream;

	
	//uses ParseLine to load settings to p_list
	bool Load(std::string fname);
	Node<std::string> ParseLine(std::string* line);
	
};



	



#endif //FILE_STORAGE_H
